k=(1:.01:15);
golden_inv = 2/(sqrt(5)-1);

%% Approximations
approx_log = (2.^k)/log(golden_inv);
approx_no_magic = 2.^(k+1);
approx = (approx_no_magic-.5);
exact=1./(golden_inv.^(2.^(-k))-1);

%% Errors (%)
err_norm_log = 100*abs(exact-approx_log)./exact;
err_norm_no_magic = 100*abs(exact-approx_no_magic)./exact;
err_norm = 100*abs(exact-approx)./exact;

%% Plots
ind_tmp=find(round(k)==k);
plot(k(ind_tmp),err_norm_log(ind_tmp),'og');
hold on
plot(k(ind_tmp),err_norm_no_magic(ind_tmp),'ok');
plot(k(ind_tmp),err_norm(ind_tmp),'or');
legend('\beta_k \approx 2^k/ln(\phi)','\beta_k \approx 2^{(k+1)}','\beta_k \approx 2^{(k+1)}-1/2')
plot(k,err_norm_log,'g')
plot(k,err_norm_no_magic,'k')
plot(k,err_norm,'r')
xlabel('k')
ylabel('Error / Valor Real (%)')
title('Ev. del error al usar distintas approximaciones')
hold off

%Derivada:
%http://www.wolframalpha.com/input/?i=derivate+1-%28%282%2F%28sqrt%285%29-1%29%29^%282^%28-k%29%29+-1%29*%282^%28k%2B1%29-.5%29
% esto esta mal (lo de arriba no.): err_der = (2.^k)*((sqrt(5)-1).^((-2).^(-k))).*((2.^(2.^(-k))).*(.667101*(2.^k) - 1.38629*(4.^k) - .166775) + 1.38629*(4.^k).*(sqrt(5)-1).^(2.^(-k)))